package com.uzai.console.web.sysdomain;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.sysdomain.*;
import com.uzai.console.dto.sysdomain.sysdomaindetail.SysDomainRebuyDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.sysdomain.SysDomainService;
import com.uzai.console.vo.kuaizhan.CheckDomainBanVo;
import com.uzai.console.vo.module.product.BuyProductAuthVo;
import com.uzai.console.vo.sysdomain.*;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 域名管理
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "域名管理",tags = "域名管理")
@ApiSort(17)
@RestController
public class SysDomainController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(SysDomainController.class);

    @Autowired
    private SysDomainService sysDomainService;

    @ApiOperation(value = "分页查询快站域名列表", notes = "分页查询快站域名列表", response = SysDomainKuaizhanInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/sysDomain/findSysDomainKuaizhanList")
    public Object findSysDomainKuaizhanList(@RequestBody SysDomainQuery sysDomainQuery){
        sysDomainQuery.setType(1);//快站域名
        return sysDomainService.findSysDomainKuaizhanList(sysDomainQuery);
    }

    @ApiOperation(value = "查询快站域名价格", notes = "查询快站域名价格", response = SysDomainKuaizhanPriceVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/sysDomain/findSysDomainKuaizhanPrice")
    public Object findSysDomainKuaizhanPrice(){
        return sysDomainService.findSysDomainKuaizhanPrice();
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.BUY)
    @ApiOperation(value = "购买快站域名", notes = "购买快站域名", response = BuySysDomainVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/sysDomain/buySysDomainKuaizhan")
    public Object buySysDomainKuaizhan(@RequestBody SysDomainBuyDto sysDomainBuyDto){
        return sysDomainService.buySysDomainKuaizhan(sysDomainBuyDto);
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.BUY)
    @ApiOperation(value = "快站域名续费", notes = "快站域名续费",response = BuySysDomainVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/sysDomain/rebuySysDomainKuaizhan")
    public Object rebuySysDomainKuaizhan(@RequestBody SysDomainRebuyDto sysDomainRebuyDto){
        return sysDomainService.rebuySysDomainKuaizhan(sysDomainRebuyDto);
    }

    @ApiOperation(value = "查询系统快站域名详情", notes = "查询系统快站域名详情", response = SysDomainKuaizhanInfoVo.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/sysDomain/findSysDomainKuaizhanInfo")
    public Object findSysDomainKuaizhanInfo(@RequestBody SysDomainIdDto sysDomainIdDto){
        return sysDomainService.findSysDomainKuaizhanInfo(sysDomainIdDto);
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "获取随机二级域名", notes = "获取随机二级域名", response = RandomDomainVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/sysDomain/getRandomDomain")
    public Object getRandomDomain(){
        return sysDomainService.getRandomDomain();
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "编辑系统快站域名", notes = "编辑系统快站域名")
    @ApiOperationSupport(order = 5)
    @PostMapping("/sysDomain/updateSysDomainKuaizhan")
    public Object updateSysDomainKuaizhan(@RequestBody SysDomainKuaizhanDto sysDomainKuaizhanDto){
        sysDomainService.updateSysDomainKuaizhan(sysDomainKuaizhanDto);
        return true;
    }

    @ApiOperation(value = "检测快站域名是否封禁", notes = "检测快站域名是否封禁", response = CheckDomainBanVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/sysDomain/checkSysDomainKuaizhan")
    public Object checkSysDomainKuaizhan(@RequestBody SysDomainIdDto sysDomainIdDto){
        return sysDomainService.checkSysDomainKuaizhan(sysDomainIdDto);
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "生成快站域名共享码", notes = "生成快站域名共享码")
    @ApiOperationSupport(order = 6)
    @PostMapping("/sysDomain/createShareCode")
    public Object createShareCode(@RequestBody SysDomainIdDto sysDomainIdDto){
        return sysDomainService.createShareCode(sysDomainIdDto);
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "添加共享快站域名", notes = "添加共享快站域名")
    @ApiOperationSupport(order = 6)
    @PostMapping("/sysDomain/addSysDomainByShareCode")
    public Object addSysDomainByShareCode(@RequestBody SysDomainShareCodeDto sysDomainShareCodeDto){
        sysDomainService.addSysDomainByShareCode(sysDomainShareCodeDto);
        return true;
    }

    @ApiOperation(value = "查询系统自用域名列表", notes = "查询系统自用域名列表", response = SysDomainPrivateInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/sysDomain/findSysDomainPrivateList")
    public Object findSysDomainPrivateList(@RequestBody SysDomainQuery sysDomainQuery){
        sysDomainQuery.setType(2);//自用域名
        return sysDomainService.findSysDomainPrivateList(sysDomainQuery);
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加系统自用域名", notes = "添加系统自用域名")
    @ApiOperationSupport(order = 8)
    @PostMapping("/sysDomain/addSysDomainPrivate")
    public Object addSysDomainPrivate(@RequestBody SysDomainPrivateDto sysDomainPrivateDto){
        sysDomainService.addSysDomainPrivate(sysDomainPrivateDto);
        return true;
    }

    @ApiOperation(value = "查询系统自用域名详情", notes = "查询系统自用域名详情", response = SysDomainPrivateInfoVo.class)
    @ApiOperationSupport(order = 9)
    @PostMapping("/sysDomain/findSysDomainPrivateInfo")
    public Object findSysDomainPrivateInfo(@RequestBody SysDomainIdDto sysDomainIdDto){
        sysDomainService.findSysDomainPrivateInfo(sysDomainIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改系统自用域名", notes = "修改系统自用域名")
    @ApiOperationSupport(order = 10)
    @PostMapping("/sysDomain/updateSysDomainPrivate")
    public Object updateSysDomainPrivate(@RequestBody SysDomainPrivateDto sysDomainPrivateDto){
        sysDomainService.updateSysDomainPrivate(sysDomainPrivateDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除域名", notes = "删除域名")
    @ApiOperationSupport(order = 11)
    @PostMapping("/sysDomain/deleteSysDomain")
    public Object deleteSysDomain(@RequestBody SysDomainIdDto sysDomainIdDto){
        sysDomainService.deleteSysDomain(sysDomainIdDto);
        return true;
    }

//    @SystemLogType(model = SystemModelEnum.SysDomain, type = OperationTypeEnum.UPLOAD)
//    @ApiOperation(value = "下载源码", notes = "下载源码")
//    @ApiOperationSupport(order = 12)
//    @GetMapping("/sysDomain/downloadSourceCode")
//    public void downloadSourceCode(){
//        sysDomainService.downloadSourceCode(getResponse());
//    }

    @ApiOperation(value = "获取下载源码地址", notes = "获取下载源码地址", response = SourceCodeDownloadUrl.class)
    @ApiOperationSupport(order = 13)
    @PostMapping("/sysDomain/getDownloadSourceCodeUrl")
    public Object getDownloadSourceCodeUrl(){
        return sysDomainService.getDownloadSourceCodeUrl();
    }



}
